<?php
namespace app\admin\controller;

use app\admin\service\AccountService;
use think\Controller;

/**
 * Class Account
 * @package app\admin\controller
 */
class Account extends Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 登录
     * @return \think\response\View
     */
    public function login()
    {
        return view();
    }

    /**
     * 验证登录
     * @return array
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function checkLogin()
    {
        $rJson = [];
        $mobile = input('post.mobile');
        $password = input('post.password');
        $accountService = new AccountService();
        if ($accountService->getCheckLogin($mobile, $password)) {
            $rJson['success'] = true;
        } else {
            $rJson['success'] = false;
            $rJson['data']['error'] = $accountService->getError();
        }
        return $rJson;
    }

    /**
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function reset_password()
    {
        if (request()->isPost()) {
            return json((new AccountService())->reset_password());
        }
        $this->assign('user',session('user'));
        return view();
    }
}
